﻿using System;
using System.Activities;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NMemcached.Client.Test
{
    [TestClass]
    public class ActivityTests
    {
        [TestMethod]
        public void ActivityTest()
        {
            IDictionary<string, object> inArgs = new Dictionary<string, object>();

            AsyncMemcachedClient client = new AsyncMemcachedClient(MemcachedSettings.Servers);
            client.IncludeCacheMisses = true;
            client.ConnectionError += new EventHandler<ConnectionEventArgs>(MemcachedSettings.ErrorHandler);

            inArgs.Add("Connection", client);

            MemcachedWorkflow workflow = new MemcachedWorkflow();

            //Call the flush on the cache servers before running the workflow
            client.FlushAll();

            IDictionary<string, object> output = WorkflowInvoker.Invoke(workflow, inArgs);

            IDictionary<string, object> items = (IDictionary<string, object>)output["Multiple"];
            IDictionary<string, CacheDetail> details = (IDictionary<string, CacheDetail>)output["MultipleDetail"];
            object casValue = output["CasSetValue"];
            object inc = output["IncrementValue"];
            object dec = output["DecrementValue"];

            Assert.IsNotNull(items);
            Assert.IsNotNull(details);
            Assert.IsNotNull(casValue);
            Assert.IsNotNull(inc);
            Assert.IsNotNull(dec);

            Assert.IsTrue(items.Count == 4);
            Assert.IsTrue(details.Count == 4);

            Assert.AreEqual((ulong)44, inc);
            Assert.AreEqual((ulong)30, dec);
        }
    }
}
